#define _CRT_SECURE_NO_WARNINGS


#include<iostream>
#include<vector>

using namespace std;

int search(vector<int>& nums, int target) {
  
    int left = 0;
    int right = nums.size() - 1;
    int mid = (right - left) / 2;


    while (left <= right)
    {

        if (target == nums[mid])
        {
            return mid;
        }
        else if (target < nums[mid])
        {
            right = mid - 1;
        }
        else {

            left = mid + 1;
        }
        mid = (right - left) / 2+left;
    }
    return -1;

}

int removeElement(vector<int>& nums, int val) {
    if (nums.size() == 0)
    {
        return 0;
    }

    int left = 0;
    int right = nums.size() - 1;
    int count = 0;
    while (left < right) {
        while (right > 0 && nums[right] == val) {
            right--;
        }
        while (left < nums.size() && nums[left] != val) {
            left++;
        }
        if (left < right) {
            swap(nums[left], nums[right]);
        }
    }
    int i = 0;
    for (auto e : nums)
    {
        if (e != val)
        {
            count++;
        }
    }

    return count;
}
}

int main()
{
    vector<int> nums = { -1,0,3,5,9,12 };
    vector<int> nums1 = { 3,3 };
    //cout << search(nums, 2) << endl;
    cout << removeElement(nums1, 5)<<endl;
}

/*
*   */